package com.tl.juc.c2;

import java.util.concurrent.*;

public class C2_CustomeThreadPool {
    public static void main(String[] args) {
        ExecutorService threadPool = new ThreadPoolExecutor(10,20,0L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        class MyTask implements Runnable{
             int i =0;
             public MyTask(int i){
                 this.i=i;
             }
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"程序员做第"+i+"个项目");
                try{
                    Thread.sleep(3000);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }

        try{
            for (int i=1;i<100;i++){
                MyTask myTask = new MyTask(i);
                threadPool.execute(myTask);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            threadPool.shutdown();
        }
    }
}
